package streamdef;

import java.util.Vector;

public class SubCondition {
	// is it AND or OR ?
	private boolean isANDStatement;
	// once set -> all have to be AND or OR !
	private boolean AndOrTypeIsSet;

	// OR/AND-statement -> more than one statement possible
	private Vector<ConditionStatement> conditionStatements;

	// storage of all the used stream IDs
	// the IDs are the internal ones (defined in the FROM-statement)
	private Vector<Long> usedInternalStreamIDs; // limited to TWO

	public SubCondition() {
		conditionStatements = new Vector<ConditionStatement>();
		usedInternalStreamIDs = new Vector<Long>();
		AndOrTypeIsSet = false;
		isANDStatement = true;
	}

	protected void finalize() {
		conditionStatements.clear();
		usedInternalStreamIDs.clear();
	}

	public boolean isANDStatement() {
		return isANDStatement;
	}

	public void setANDStatement(boolean bool) {
		isANDStatement = bool;
		AndOrTypeIsSet = true;
	}

	public boolean AndOrTypeIsSet() {
		return AndOrTypeIsSet;
	}

	public Vector<ConditionStatement> getQueryStatements() {
		return conditionStatements;
	}

	public void addQueryStatement(ConditionStatement stat) {
		conditionStatements.add(stat);
		if (stat.type == streamdef.DEFINES.ConditionStatementType.FIELD_ONESTREAM)
			addInternalStreamID(((ConditionStatementFieldFromOneStream) stat).internalStreamID);
		else if (stat.type == streamdef.DEFINES.ConditionStatementType.FIELD_TWOSTREAMS) {
			addInternalStreamID(((ConditionStatementFieldFromTwoStreams) stat).internalStreamID1);
			addInternalStreamID(((ConditionStatementFieldFromTwoStreams) stat).internalStreamID2);
		} else if (stat.type == streamdef.DEFINES.ConditionStatementType.TIMERELATION_TWOSTREAMS) {
			addInternalStreamID(((ConditionStatementTimeRelationTwoStreams) stat).internalStreamID1);
			addInternalStreamID(((ConditionStatementTimeRelationTwoStreams) stat).internalStreamID2);
		}
	}

	public Vector<Long> getUsedInternalStreamIDs() {
		return usedInternalStreamIDs;
	}

	public void addInternalStreamID(long internalStreamID) {
		usedInternalStreamIDs.add(internalStreamID);
	}
}
